pp108 : Customizing SOAP Fault

Customizing SOAP Fault

 


The busdataisland throws events when the content sent to the gateway for processing fails before or during the execution of a method. Such errors, sent by the gateway to the busdataisland, are called SOAP Faults. The onsoapfault event is fired for SOAP Faults.
Soap Faults may occur for the following reasons:

  • Request was not processed. This happens when the SOAP Container or Service Group to which the request is sent is not started.
  • Request sent to the receiver failed during an insert operation.
  • Request sent to the receiver failed during an update operation.
  • Request sent to the receiver failed during a delete operation.
  • Request size was too big, due to which it was not processed. This results in a timeouterror.

Following is a sample of an old SOAP fault, received during the insertion of a record to the database:

<SOAP:Fault sync_id="0" xmlns="http://schemas.cordys.com/1.0/demo/northwind">
    <SOAP:faultcode>Server.WriteError</SOAP:faultcode>
    <SOAP:faultstring>Database update failed</SOAP:faultstring>
    <SOAP:detail>
        <tuple sync_id="0">
            <new>
                <Employees>
                    <LastName>Test</LastName>
                    <FirstName>Test</FirstName>
                </Employees>
            </new>
            <error TYPE="Enumeration">
                <elem>conversion of parameter EmployeeID failed</elem>
            </error>
        </tuple>
    </SOAP:detail>
</SOAP:Fault>

The old SOAP fault returned by the gateway contains the following tags:

  • faultcode- It indicates the type of the fault. This can be a ReadError or a WriteError.
  • faultstring- It indicates the actual error that has occurred at the gateway such as 'Database update failed' and 'Failed to reach metadata'.
  • detail- It contains information about the error that occurred during processing. For errors involving databases, such as errors pertaining to update, insertion, and deletion operations, the SOAP:detail consists of the tuples involved in the operation.

Following is a sample of a new SOAP fault, received during the insertion of a record to the database:

<script id="soapFaultViewerapplication" type="cordys/xml">
    <Application focus="false">
        <description>Custom Error</description>
        <caption>Custom Error</caption>
        <url>/cordys/wcp/behavior/data/soapFaultViewer.htm</url>
        <id>soapFaultViewer</id>
        <frame features="dialogHeight:200px;dialogWidth:420px;help:no;status:no;scroll:no">_modal</frame>
    </Application>
</script>

To display a custom error, the faultCode and faultString properties of the onsoapfault event should be modified, and the event object should be sent as a parameter to the showSOAPFault() method. The following code modifies both the properties in the handler of the onsoapfault event:

<!-- Data Island definition in HTML -->
<div cordysType="wcp.library.data.BusDataIsland" id="bdiEmployees" request="request.XMLDocument" onsoapfault="handleCustomError()"></div>
//Handler code in JScript
function handleCustomError()
{
    //First, cancel the default alert to be shown by setting showError property to false
    event.showError = false;
    //Modify the fault properties of the event
    event.faultCode = "Custom Fault Code";
    event.faultString = "An error has occurred in the back end while processing the request";
    //Call the showSOAPFault() API of UFO. Pass event as parameter
    application.showSOAPFault(event);
}

The custom error message for the SOAP Fault is displayed as follows: